package br.edu.fafica.medico.acao;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.edu.fafica.medico.dao.JdbcMedicoDAO;
import br.edu.fafica.medico.dao.MedicoDAO;
import br.edu.fafica.model.Medico;

public class AcaoPesquisarMedico implements AcaoMedico{

	@Override
	public void executarMedico(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException,
			SQLException {
		// TODO Auto-generated method stub
		
		MedicoDAO medicoDAO = new JdbcMedicoDAO();
		
		String campo = request.getParameter("slcCampo");
		String valor = request.getParameter("txtValor");
		
		List<Medico> medico = medicoDAO.buscarMedicos(campo, valor);
		
		
		request.setAttribute("medicos", medico);
		request.setAttribute("countMedicos", "Foram retornados: " + medico.size() + " registro(os)");
				
		
		RequestDispatcher dispatcher = 
				request.getRequestDispatcher("/formListarMedico.jsp");
		dispatcher.forward(request, response);
		
	}

}
